#import "UIImageEx.h"


@implementation UIImage(Resizing)

- (UIImage*)scaleToSize:(CGSize)size {
	
	UIGraphicsBeginImageContext(size);
	
	CGContextRef context = UIGraphicsGetCurrentContext();
	
	CGContextTranslateCTM(context, 0.0, size.height);
	
	CGContextScaleCTM(context, 1.0, -1.0);
	
	CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), self.CGImage);
	
	UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
	
	UIGraphicsEndImageContext();
	
	return scaledImage;
	
}

-(UIImage *)changeWhiteColorTransparent{
	CGImageRef rawImageRef=self.CGImage;
	
	const float colorMasking[6] = {222, 255, 222, 255, 222, 255};
	
	UIGraphicsBeginImageContext(self.size);
	CGImageRef maskedImageRef=CGImageCreateWithMaskingColors(rawImageRef, colorMasking);
	{
		//if in iphone
		CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0.0, self.size.height);
		CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0); 
	}
	
	CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, self.size.width, self.size.height), maskedImageRef);
	UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
	CGImageRelease(maskedImageRef);
	UIGraphicsEndImageContext();    
	return result;
}	

@end